﻿<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  <CustomAction
  Id="PSProvisionerScriptGallery.Validate.Button"
  RegistrationType="List"
  RegistrationId="10003"
  Location="CommandUI.Ribbon.EditForm"
  Sequence="5"
  UIVersion="4"
  Title="Validate">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.ListForm.Edit.Commit.Controls._children">
          <Button
            Id="PSProvisionerScriptGallery.Validate.Button"
            Sequence="5"
            Alt="Validate Provisioner Script"
            Command="PSProvisionerScriptGallery.Validate.Button.Clicked"
            LabelText="Validate"
            Image16by16="/_layouts/$Resources:core,Language;/images/formatmap16x16.png" Image16by16Top="-64" Image16by16Left="-128"
            Image32by32="/_layouts/$Resources:core,Language;/images/formatmap32x32.png" Image32by32Top="-128" Image32by32Left="-256"
            TemplateAlias="o1"
        />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
          Command="PSProvisionerScriptGallery.Validate.Button.Clicked"
          CommandAction="javascript:function getElementsByClass(searchClass,node,tag) {var classElements = new Array();if ( node == null )node = document;if ( tag == null )tag = '*';var els = node.getElementsByTagName(tag);var elsLen = els.length;var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');	for (i = 0, j = 0; i &lt; elsLen; i++) {		if ( pattern.test(els[i].className) ) {			classElements[j] = els[i];			j++;		}	}	return classElements;} var txt=getElementsByClass('ms-formbody')[2].getElementsByTagName('textarea')[0].value; var parser; if (window.DOMParser) {parser=new DOMParser(); xmlDoc=parser.parseFromString(txt,'text/xml');} else {parser=new ActiveXObject('Microsoft.XMLDOM');parser.async='false'; parser.loadXML(txt);}; if(parser.documentElement == null || parser.documentElement.nodeName=='parsererror') alert('Invalid snippet'); else alert('OK');  " />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>


  <CustomAction
    Id="PSProvisionerScriptGallery"
    GroupId="Galleries"
    Location="Microsoft.SharePoint.SiteSettings"
    Title="Provisioner scripts"
    Sequence="1000"
    RequireSiteAdministrator="TRUE"
    >
    <UrlAction Url="~sitecollection/_catalogs/provisionerscripts" />
  </CustomAction>

  <CustomAction
    Id="PSProvisionerScriptDebug"
    GroupId="SiteAdministration"
    Location="Microsoft.SharePoint.SiteSettings"
    RequireSiteAdministrator="TRUE"
    Title="Test provisioner scripts"
    >
    <UrlAction Url="~site/_layouts/PS.Practices.Provisioner/ApplyScript.aspx"/>
  </CustomAction>
  
  <ListInstance Title="Provisioner Scripts"
                OnQuickLaunch="FALSE"
                TemplateType="10003"
                Url="_catalogs/provisionerscripts" Hidden="TRUE" 
                Description="Provisioner Script Library">
    <Data>
      <Rows>
        <Row>
          <Field Name="Title">Sample Provisioner Script</Field>
          <Field Name="Templates">STS#0</Field>
          <Field Name="Script">
            <![CDATA[<Provisioner>

 <FixupWebACL RespectInheritanceSetting="false" RoleAssignments="BreakClean" SyncGroupQuickLaunch="true">
  <SiteGroup Action="Create" Name="{{SPWeb.Title}} Owners" Description="Test - {{SPWeb.Description}}"
    AllowMembersEditMembership="true" AllowRequestToJoinLeave="true"
    AutoAcceptRequestToJoinLeave="true" OnlyAllowMembersViewMembership="false"
    RequestToJoinLeaveEmailSetting="administrator@wss-server.com" 
    Owner="WSS-SERVER\administrator" />
  <SiteGroup Action="Create" Name="{{SPWeb.Title}} Members"  />
  <AssociateSiteGroup Name="{{SPWeb.Title}} Owners" Role="Owner" />
  <AssociateSiteGroup Name="{{SPWeb.Title}} Members" Role="Member" />
 </FixupWebACL>

<ProvisionWebs>
  <Web Title="Sub Web1" Description="Blah"  Template="STS#1" Url="subweb1" LCID="1033" UniquePermissions="true" InheritTopNav="true"  />
  <Web Title="Sub Web2" Template="STS#1">
   <Web Title="Sub Web to Sub Web2" Template="STS#1" />
  </Web>
 </ProvisionWebs>
</Provisioner>
]]></Field>
        </Row>
        <Row>
          <Field Name="Title">Sample Provisioner UI</Field>
          <Field Name="Templates">STS#1</Field>
          <Field Name="Script">
            <![CDATA[
<Provisioner>
	<FixupWebACL RespectInheritanceSetting="false" RoleAssignments="BreakClean" SyncGroupQuickLaunch="true">
	<SiteGroup Action="Create" Name="{{SPWeb.Title}} Owners" Description="Test - {{SPWeb.Description}}"
		AllowMembersEditMembership="true" AllowRequestToJoinLeave="true"
		AutoAcceptRequestToJoinLeave="true" OnlyAllowMembersViewMembership="false"
		RequestToJoinLeaveEmailSetting="administrator@wss-server.com" 
		Owner="WSS-SERVER\administrator" />
	<SiteGroup Action="Create" Name="{{SPWeb.Title}} Members"  />
	<AssociateSiteGroup Name="{{SPWeb.Title}} Owners" Role="Owner" />
	<AssociateSiteGroup Name="{{SPWeb.Title}} Members" Role="Member" />
	</FixupWebACL>
	<ProvisionLists>
		<List Title="Site Information List">
			<ListItem SyncWithPropertyBag="true">
				<Column FieldName="WebTitle">{{SPWeb.Title}}</Column>
				<Column FieldName="WebDescription">{{SPWeb.Description}}</Column>
			</ListItem>
		</List>
	</ProvisionLists>
	<ProvisionWebs>
		<Web Title="Human Resources" Description="Human Resources Site"  Template="STS#1" Url="human_resources" LCID="1033" UniquePermissions="true" InheritTopNav="true">
			<Actions>
				<ProvisionLists>
					<List Title="Site Information List">
						<ListItem>
							<Column FieldName="Title">{{Property.Title}} - Human Resources</Column>
							<Column FieldName="ClientName">{{ParentWeb.Title}}</Column>
							<Column FieldName="ProjectName">Human Resources</Column>
							<Column FieldName="WebTitle">{{SPWeb.Title}}</Column>
							<Column FieldName="WebDescription">{{SPWeb.Description}}</Column>
						</ListItem>
					</List>
				</ProvisionLists>
			</Actions>
		</Web>
	</ProvisionWebs>
</Provisioner>
]]></Field>
          <Field Name="ContentType0">Provisioner User Interface</Field>
          <Field Name="WebUrl">SampleUrl{{Property.ClientName}}</Field>
          <Field Name="WebTitle">SampleTitle - {{Property.ProjectName}}</Field>
        </Row>
      </Rows>
    </Data>
  </ListInstance>  
  
 
</Elements>
